#include "../include/OEFReader.h"
#include <iostream>
#include <fstream>
#include <string>
#define ARRAY_SIZE
OEFReader::OEFReader(const std::string &fileName):m_file(fileName)
{
    m_data.resize(16384);
    m_code.resize(16384);
    openFile();
}

OEFReader::~OEFReader()
{
    /// ненужная строчка
}

void OEFReader::openFile()
{
    m_index = 0;
    m_input.open(m_file.c_str(), std::ifstream::binary);
    if (m_input.fail())
        return;
    while (!m_input.eof())     // loop while extraction from file is possible
    {
        m_input.read(m_buff, 12);       // get character from file
        parseCommand(m_buff, m_index);
        m_index++;
    }
    m_input.close();
}

void OEFReader::parseCommand(const char *buff, int index)
{
    bool isEven = index%2==0;
    double data = 0.0;
    long int code = 0;
    if (isEven)
        {
            data = *(double*)(buff);
            code = *(buff+8);
        }
    else
        {
            code = *(buff);
            data = *(double*)(buff+4);
        }
    std::cout.setf ( std::ios::hex, std::ios::basefield );
    std::cout << "index : "<< index <<" data = " << data << "; code = " << code << std::endl;

}
